// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

package com.android.tools.r8.classmerging.vertical;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class NestedDefaultInterfaceMethodsTestDump {

  // Generated by running ./tools/asmifier.py build/test/examplesAndroidO/classes/classmerging/-
  // NestedDefaultInterfaceMethodsTest\$C.class, and changing "invoke-special B.m()" to "invoke-
  // special A.m()".
  public static class CDump implements Opcodes {

    public static byte[] dump() {
      ClassWriter cw = new ClassWriter(0);
      FieldVisitor fv;
      MethodVisitor mv;
      AnnotationVisitor av0;

      cw.visit(
          V1_8,
          ACC_PUBLIC + ACC_SUPER,
          "classmerging/NestedDefaultInterfaceMethodsTest$C",
          null,
          "java/lang/Object",
          new String[] {"classmerging/NestedDefaultInterfaceMethodsTest$B"});

      cw.visitInnerClass(
          "classmerging/NestedDefaultInterfaceMethodsTest$C",
          "classmerging/NestedDefaultInterfaceMethodsTest",
          "C",
          ACC_PUBLIC + ACC_STATIC);

      cw.visitInnerClass(
          "classmerging/NestedDefaultInterfaceMethodsTest$B",
          "classmerging/NestedDefaultInterfaceMethodsTest",
          "B",
          ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT + ACC_INTERFACE);

      {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
      }
      {
        mv = cw.visitMethod(ACC_PUBLIC, "m", "()V", null, null);
        mv.visitCode();
        mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
        mv.visitLdcInsn("In C.m()");
        mv.visitMethodInsn(
            INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
        mv.visitVarInsn(ALOAD, 0);
        // The signature "classmerging/NestedDefaultInterfaceMethodsTest$B" has been changed to
        // "classmerging/NestedDefaultInterfaceMethodsTest$A".
        mv.visitMethodInsn(
            INVOKESPECIAL, "classmerging/NestedDefaultInterfaceMethodsTest$A", "m", "()V", true);
        mv.visitInsn(RETURN);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
      }
      cw.visitEnd();

      return cw.toByteArray();
    }
  }
}
